import Vue from 'vue'
import Router from 'vue-router'
import store from "@/store/store";
Vue.use(Router)
import Login from 'comp/common/header/components/Login'
import Register from 'comp/common/header/components/Register'
import HomePage from 'comp/HomePage/HomePage'
import VideoAndArticle  from 'comp/videoAndArticle/VideoAndArticle'
import VideoAndArticleDetails  from 'comp/videoAndArticle/components/Details'
import Catering from "comp/catering/Catering";
import Store from 'comp/store/Store'
import Community from 'comp/community/Community'
import CommunityDetails from 'comp/community/components/Details'
import CommunityRelease from 'comp/community/components/Release'

import Setting from 'comp/common/setting/Setting'
import SettingInformation from 'comp/common/setting/components/Information'
import SettingMessages from 'comp/common/setting/components/Messages'
import SettingPunch from 'comp/common/setting/components/Punch'
import SettingRecommend from 'comp/common/setting/components/Recommend'




const router= new Router({
  mode:'hash',
  routes: [
    {
      path: '/',redirect: '/homePage',
      component: HomePage
    },
    {
      path: '/index.html',redirect: '/homePage',
      component: HomePage
    },
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/register',
      name: 'Register',
      component: Register
    },
    {
      path: '/setting',
      name: 'Setting',
      component: Setting,
      children:[
        {
          path:'settingInformation',
          name:'SettingInformation',
          component:SettingInformation
        },{
          path:'settingMessages',
          name:'SettingMessages',
          component:SettingMessages
        },{
          path:'settingPunch',
          name:'SettingPunch',
          component:SettingPunch
        },{
          path:'settingRecommend',
          name:'SettingRecommend',
          component:SettingRecommend
        },
      ]
    },
    {
      path: '/homePage',
      name: 'HomePage',
      component: HomePage
    },
    {
      path: '/videoAndArticle',
      name: 'VideoAndArticle',
      component: VideoAndArticle,
      meta:{
        auth:true
      }
    },
    {
      path:'/videoAndArticleDetails',
      name:'VideoAndArticleDetails',
      component:VideoAndArticleDetails,
      meta:{
        auth:true
      }
    },
    {
      path: '/catering',
      name: 'Catering',
      component: Catering,
      meta:{
        auth:true
      }
    },
    {
      path: '/store',
      name: 'Store',
      component: Store,
      meta:{
        auth:true
      }
    },
    {
      path: '/community',
      name: 'Community',
      component: Community,
      meta:{
        auth:true
      }
    },{
      path: '/communityDetails/:id',
      name: 'CommunityDetails',
      component: CommunityDetails,
      meta:{
        auth:true
      }
    },
    {
      path: '/communityRelease',
      name: 'CommunityRelease',
      component: CommunityRelease,
      meta:{
        auth:true
      }
    },
  ]
});
router.beforeEach((to,from,next)=>{
  if(to.meta.auth){
    //该路由需要登录才能访问
    if(store.state.token){
      //登录已经完成
      next();
    }else{
      router.app.$notify({
        title: '警告',
        message: "请您先登录！",
        type: 'warning'
      });
      next({
        path:'/login'
    });
    }
  }else{
    next();//不调用这个方法可能会页面卡住
  }
})

export default router;
